package com.yitong.equipment.ui.viewmodel

import android.app.Application
import android.util.Log
import androidx.annotation.NonNull
import androidx.lifecycle.MutableLiveData
import com.yitong.equipment.base.BaseViewModel
import com.yitong.equipment.entity.other.InterfaceConfigBean
import com.yitong.equipment.ext.getInterfaceConfig
import com.yitong.equipment.ext.saveAppConfig
import com.yitong.equipment.network.ApiCallback
import com.yitong.equipment.network.SubscriberCallBack
import io.reactivex.disposables.Disposable

class WelcomeViewModel(@NonNull application: Application) : BaseViewModel(application) {

    var welData = MutableLiveData<Boolean>()

    /**
     * 获取APP全局配置
     */
    fun getConfig() {
        apiService.getAppConfig(getInterfaceConfig()).execute(SubscriberCallBack(object : ApiCallback<InterfaceConfigBean> {

            override fun onSuccess(interfaceConfigBean: InterfaceConfigBean) {
                Log.d("interfaceConfigBean", interfaceConfigBean.toString())
                saveAppConfig(interfaceConfigBean)
            }

            override fun onFailure(code: Int, msg: String?) {
            }

            override fun onSubscribe(d: Disposable?) {
                addDisposable(d)
            }

            override fun onCompleted() {
                welData.value = true
            }

        }))

    }
}